<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <div>{{ message }}</div>
    <my-component></my-component>
    <!-- <MyComponent></MyComponent> -->
    <sub-component></sub-component>
  </div>

  <script src="./libs/vue.js"></script>
  <script>

    // 组件选项
    const subOptions = {
      template: `
        <h3>局部注册组件渲染的内容</h3>
      `
    }

    // 定义组件的选项对象
    const options = {
      // 组件所关联的视图模板
      template: `
        <div>
          <h1>{{ title }}</h1>
          <h2>{{ getSubTitle() }}</h2>
          <sub-component></sub-component>
        </div>
      `,
      data() {
        return  {
          title: '主标题'
        }
      },
      methods: {
        getSubTitle() {
          return '这是方法中的副标题'
        }
      },
      // 局部组件注册
      components: {
        'sub-component': subOptions
      }
    }

    // 全局注册组件
    Vue.component('my-component', options)
    // Vue.component('MyComponent', options)

    new Vue({
      el: '#app',
      data: {
        message: 'Hello'
      }
    })
  </script>
</body>
</html>